package com.demo.com.p_c_allwait_fix;


/**
 * Desc: 生产者
 * @author: lisha 2018/7/5 9:51
 */

public class P {
    private String lock;

    public P(String lock) {
        this.lock = lock;
    }

    public void setValue() {
        try {
            synchronized (lock) {
                while (!ValueObject.value.equals("")) {
                    System.out.println("生产者"
                            + Thread.currentThread().getName()
                            + "waitting 了" );
                    lock.wait();
                }
                System.out.println("生产者"
                        + Thread.currentThread().getName()
                        + "running 了" );
                String value =  System.currentTimeMillis() + "_" + System.nanoTime();
                System.out.println("set的值是：" + value);
                ValueObject.value = value;
                // 唤醒所有线程
                lock.notifyAll();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
